
function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}
var kssctn="";
function SendRemark() {
	kssctn = getCookie("ks-s-ctn");
	var count=0;
	$(".left").each(function (i, e) {
		var orderId = $(e).children("a").text();
		var date = {"oid": orderId,"flagTagCode":"green_flag_tag_order","note":"1M"};
		$.ajax({
			url:"https://s.kwaixiaodian.com/rest/app/tts/cs/ref",
			type:"post",
			success:function(obj){ 
				if(obj.result==1){
					kssctn = getCookie("ks-s-ctn")
					console.log(kssctn);
				}
			},
			dataType:"json",
			contentType: 'application/json',
			async:false
		})
		$.ajax({
			url:"https://s.kwaixiaodian.com/rest/app/tts/ks/seller/order/noteAndFlag/add",
			beforeSend: function (XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("ks-s-ctn", kssctn);
			 },
			type:"post",
			data: JSON.stringify(date),
			success:function(obj){
				if(obj.result==1){
					count++;
				}
			},
			dataType:"json",
			contentType: 'application/json',
			async:false
		})
	})
	return count;
}
$(function () {
	$(document).keydown(function (event) {
		if (event.keyCode == 13) {
			var successCount = SendRemark();
			alert("备注完毕"+"成功"+successCount+"个");
		}
	});
})